﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IGGCore;

namespace IGGWindowApp.Panels
{
    public partial class PanelInGame : UserControl
    {
        // EVENTS
        public delegate void ItemSelectedHandler(string item);
        public event ItemSelectedHandler ItemSelected;

        public PanelInGame()
        {
            InitializeComponent();
        }

        private void panelTitle_ItemSelected(string item)
        {
            ItemSelected(item);
        }

        public void SetPics(Image imgPitch, Image imgBat)
        {
            this.pbAtTheMound.Image = imgPitch;
            this.pictureBox1.Image = imgBat;
        }

        public void SetData(Game game, string box, Player[] stars)
        {
            txtBox.Text = box;
            if (stars.Length > 0)
            {
                this.pbAtTheMound.Image = stars[0].Pic;
                txtBoxPitchingA.Text = stars[0].TeamAbbr + " MVP:" + Environment.NewLine
                    + stars[0].NameDisplay + Environment.NewLine
                    + stars[0].GameLines[0];
                this.pictureBox1.Image = stars[1].Pic;
                this.txtBatter.Text = stars[1].TeamAbbr + " MVP:" + Environment.NewLine
                    + stars[1].NameDisplay + Environment.NewLine
                    + stars[1].GameLines[0];
            }
            if (game.Status.Indicator.IsTerminated == false)
            {
                string pitcher = game.Status.CurrentPitcher.FullName;
                pitcher += " (" + game.Status.CurrentPitcher.ERA + ")" + Environment.NewLine;
                pitcher += game.Status.CurrentPitcher.IP + " innings" + Environment.NewLine;
                pitcher += game.Status.CurrentPitcher.EarnedRuns + " ER" + Environment.NewLine;
                if (game.Status.CurrentPitcher.StrikeOuts > 0)
                {
                    pitcher += game.Status.CurrentPitcher.StrikeOuts + " SO" + Environment.NewLine;
                }
                //else if (game.Status.CurrentPitcher.BB > 0)
                //{
                //    pitcher += game.Status.CurrentPitcher.StrikeOuts + " BB" + Environment.NewLine;
                //}
                txtBoxPitchingA.Text = pitcher;

                string batter = game.Status.CurrentBatter.FullName + Environment.NewLine;
                batter += game.Status.CurrentBatter.Hits + " / " + game.Status.CurrentBatter.Ab + Environment.NewLine;
                if (game.Status.CurrentBatter.Homeruns > 0)
                {
                    batter += game.Status.CurrentBatter.Homeruns + " hr" + Environment.NewLine;
                }
                if (game.Status.CurrentBatter.RBI > 0)
                {
                    batter += game.Status.CurrentBatter.RBI + " rbi" + Environment.NewLine;
                }
                this.txtBatter.Text = batter;
            }
        }
    }
}
